version 17

 ************************************************************************
/*																		*/
/*     	File Name: supremebias_analysis.do 								*/
/*      Authors: Elizabeth Maltby & Abigail Matthews					*/
/*      Purpose: Analysis for article: "Supreme Prejudice:				*/
/*			Examining the Supreme Court's Racial & Criminal Biases"		*/
/*																		*/
/*	*********************************************************************/


use supremebias_data.dta, clear


*********************************************************************	
**# Table 1. Justice-Case Level Models Full Models
*********************************************************************
		
*Table 1. Crime Interaction Model		
	melogit justicevote_binary ///
		c.lag_mq##i.crimetype_4cat i.targetrace_wbl ///
		deathpenalty target_notmale ///
		petitionerstate justice_female ///
		i.legalissue term minjustice || caseid:		 
		estimates store crimeint	
		
		quietly margins, at(crimetype_4cat=3 lag_mq=-3.475 (asobserved)_all)
		quietly margins, at(crimetype_4cat=(1(1)4) lag_mq=-3.475 (asobserved)_all) saving(meminideo1b, replace)
		quietly margins, at(crimetype_4cat=(1(1)4) lag_mq=3.959 (asobserved)_all) saving(memaxmq1b, replace)
		quietly margins, at(crimetype_4cat=(1(1)4) lag_mq=0.111 (asobserved)_all) saving(meavgmq1b, replace)
		

*Table 1. Race Interaction Model		
	melogit justicevote_binary ///
		c.lag_mq##i.targetrace_wbl ///
		i.crimetype_4cat deathpenalty ///
		petitionerstate target_notmale ///
		justice_female minjustice i.legalissue term  || caseid:		
		estimates store raceint
		
		quietly margins, at(targetrace_wbl=3 lag_mq=3.959 (asobserved)_all)
		quietly margins, at(targetrace_wbl=(1(1)3) lag_mq=-3.475 (asobserved)_all) saving(meminideo1a, replace)
		quietly margins, at(targetrace_wbl=(1(1)3) lag_mq=3.959 (asobserved)_all) saving(memaxideo1a, replace)
		quietly margins, at(targetrace_wbl=(1(1)3) lag_mq=0.111 (asobserved)_all) saving(meavgideo1a, replace)
		
		transform_margins invlogit(@)

		
*Table 1. Base Model
	melogit justicevote_binary ///
		i.targetrace_wbl ///
		i.crimetype_4cat deathpenalty ///
		lag_mq target_notmale ///
		petitionerstate justice_female minjustice ///
		i.legalissue term || caseid:		
		estimates store base
		
*Table 1: Full Models 
etable, estimates(base raceint crimeint) showstars showstarsnote varlab cstat(_r_b, nformat(%9.2fc)) ///
	cstat(_r_se, nformat(%9.2fc)) stars(.10 "*" .05 "**" .01 "***", attach(_r_b)) column(index) title("Full Models")


*********************************************************************
**# Figure 1. Predicted Probability of Voting for Litigant by Race, Crime, and Justice Ideology
*********************************************************************

		combomarginsplot meminideo1a meavgideo1a memaxideo1a, labels("Most Liberal Justice" "Mean Ideology" "Most Conservative Justice") ///
		xlabel(1 2 3, labsize(small)) legend(position(6) row(1) ring(1)) ///
		recast(scatter) ///
		xlabel(, nogrid) ylabel(0(.2)1)  ///
		plot1opts(lcolor(blue) mcolor(blue) msymbol(o)) ci1opt(color(blue)) ///
		plot2opts(lcolor(midgreen) mcolor(midgreen) msymbol(t)) ci2opt(color(midgreen)) ///
		plot3opts(lcolor(red) mcolor(red) msymbol(s)) ci3opt(color(red)) ///
		xtitle("Litigant's Race", size(medium)) ytitle("Likelihood Justice Votes for Litigant", size(medium)) ///
		title("") legend(region(lwidth(none))) graphregion(fcolor(white) lwidth(none)) ///
		plotregion(lwidth(none)) saving(baserace, replace)

		combomarginsplot meminideo1b meavgmq1b memaxmq1b, labels("Most Liberal Justice" "Mean Ideology" "Most Conservative Justice") /// 
		xlabel(, nogrid)  ylabel(0(.2)1) ///
		xlabel(1 "Murder" 2 `""Violent" "Crime""' 3 `""Nonviolent" "Crime""' 4 `""White Collar" "Crime""', labsize(small)) ///
		recast(scatter) ///
		legend(position(6) row(1) ring(1)) /// or recast(connected) plot1opts(lpattern("1"))
		plot1opts(lcolor(blue) mcolor(blue) msymbol(o)) ci1opt(color(blue)) ///
		plot2opts(lcolor(midgreen) mcolor(midgreen) msymbol(t)) ci2opt(color(midgreen)) ///
		plot3opts(lcolor(red) mcolor(red) msymbol(s)) ci3opt(color(red) msymbol(s)) ///
		xtitle("Litigant's Underlying Crime", size(medium))  ytitle("") ///
		title("") legend(region(lwidth(none))) graphregion(fcolor(white) lwidth(none)) plotregion(lwidth(none)) saving(crimeint, replace)

*Put it all together:
	grc1leg baserace.gph crimeint.gph, ycommon col(3) saving(figure1, replace)

*********************************************************************	
**#Table 1. Justice-Case Level Models Split Sample Analysis
*********************************************************************
		
* White Model		
	melogit justicevote_binary ///
		c.lag_mq##i.crimetype_4cat deathpenalty ///
		target_notmale petitionerstate justice_female minjustice ///
		i.legalissue term if targetrace_final==1 || caseid:
		estimates store whiteint
		
		quietly margins, at(crimetype_4cat=2 lag_mq=-3.475 (asobserved)_all)
		quietly margins, at(crimetype_4cat=(1(1)4) lag_mq=-3.475 (asobserved)_all) saving(minmqw, replace)
		quietly margins, at(crimetype_4cat=(1(1)4) lag_mq=3.959 (asobserved)_all) saving(maxmqw, replace)
		quietly margins, at(crimetype_4cat=(1(1)4) lag_mq=.111 (asobserved)_all) saving(avgmqw, replace)
		
		
* Black Model		
	melogit justicevote_binary ///
		c.lag_mq##i.crimetype_4cat deathpenalty ///
		justice_female minjustice term ///
		petitionerstate  target_notmale i.legalissue ///
		if targetrace_final==2 || caseid:
		estimates store blackint
		
		quietly margins, at(crimetype_4cat=3 lag_mq=-3.475 (asobserved)_all)		
		quietly margins, at(crimetype_4cat=(1(1)3) lag_mq=-3.475 (asobserved)_all) saving(minmqb, replace)
		quietly margins, at(crimetype_4cat=(1(1)3) lag_mq=3.959 (asobserved)_all) saving(maxmqb, replace)
		quietly margins, at(crimetype_4cat=(1(1)3) lag_mq=.111 (asobserved)_all) saving(avgmqb, replace)
		

* Latino Model
	melogit justicevote_binary ///
		c.lag_mq##i.crimetype_4cat deathpenalty ///
		justice_female minjustice term ///
		petitionerstate  target_notmale i.legalissue ///
		if targetrace_final==3 || caseid:
		estimates store latinoint		
		
		margins, at(crimetype_4cat=3 lag_mq=-3.475 (asobserved)_all)
		quietly margins, at(crimetype_4cat=(1(1)4) lag_mq=-3.475 (asobserved)_all) saving(minmql, replace)
		quietly margins, at(crimetype_4cat=(1(1)4) lag_mq=3.959 (asobserved)_all) saving(mxmql, replace)
		quietly margins, at(crimetype_4cat=(1(1)4) lag_mq=.111 (asobserved)_all) saving(avgmql, replace)

etable, estimates(whiteint blackint latinoint) showstars showstarsnote varlab cstat(_r_b, nformat(%9.2fc)) ///
	cstat(_r_se, nformat(%9.2fc)) stars(.10 "*" .05 "**" .01 "***", attach(_r_b)) column(index) title("Split Sample Analysis Models")

	
***************************************************************************
**# Figure 2. Split Samples, Predicted Probability of Voting for Litigant 
***************************************************************************

/* Correct confidence intervals to be bounded by 0 and 1 */
		use maxmqw, clear
		replace _ci_lb = 0 if _ci_lb < 0
		replace _ci_ub = 1 if _ci_ub > 1
		save maxmqw, replace

		use minmql, clear
		replace _ci_lb = 0 if _ci_lb < 0
		replace _ci_ub = 1 if _ci_ub > 1
		save minmql, replace

		use mxmql, clear
		replace _ci_lb = 0 if _ci_lb < 0
		replace _ci_ub = 1 if _ci_ub > 1
		save mxmql, replace
		
		use avgmql, clear
		replace _ci_lb = 0 if _ci_lb < 0
		replace _ci_ub = 1 if _ci_ub > 1
		save avgmql, replace

*White
		combomarginsplot minmqw avgmqw maxmqw, labels("Most Liberal Justice" "Mean Ideology" "Most Conservative Justice") ///
		xlabel(1  "Murder" 2 `""Violent" "' 3 `""Non-" "Violent""' 4 `""White" "Collar""') ///
		xlabel(, nogrid)  ///
		legend(position(6) row(1) ring(1)) ///
		recast(scatter) ///
		plot1opts(lcolor(blue) mcolor(blue) msymbol(o)) ci1opt(color(blue)) ///
		plot2opts(lcolor(midgreen) mcolor(midgreen) msymbol(t)) ci2opt(color(midgreen)) ///
		plot3opts(lcolor(red) mcolor(red) msymbol(s)) ci3opt(color(red)) ///
		xtitle("White Litigant", size(medium))  ///
		ytitle("Likelihood Justice Votes for Litigant", size(medium)) title("") saving(whiteint, replace)
		
*Black
		combomarginsplot minmqb avgmqb maxmqb, labels("Most Liberal Justice" "Mean Ideology" "Most Conservative Justice") ///
		xlabel(1  "Murder" 2 `""Violent" "' 3 `""Non-" "Violent""') ///
		xlabel(, nogrid)  ///
		legend(position(6) row(1) ring(1)) ///
		recast(scatter) ///
		plot1opts(lcolor(blue) mcolor(blue) msymbol(o)) ci1opt(color(blue)) ///
		plot2opts(lcolor(midgreen) mcolor(midgreen) msymbol(t)) ci2opt(color(midgreen)) ///
		plot3opts(lcolor(red) mcolor(red) msymbol(s)) ci3opt(color(red)) ///
		xtitle("Black Litigant", size(medium)) title("") ///
		ytitle("") saving(blackint, replace)		
		
*Latino 
		combomarginsplot minmql avgmql mxmql, labels("Most Liberal Justice" "Mean Ideology" "Most Conservative Justice") ///
		xlabel(1  "Murder" 2 `""Violent" "' 3 `""Non-" "Violent""' 4 `""White" "Collar""') ///
		xlabel(, nogrid)  ///
		legend(position(6) row(1) ring(1)) ///
		recast(scatter) ///
		plot1opts(lcolor(blue) mcolor(blue) msymbol(o)) ci1opt(color(blue)) ///
		plot2opts(lcolor(midgreen) mcolor(midgreen) msymbol(t)) ci2opt(color(midgreen)) ///
		plot3opts(lcolor(red) mcolor(red) msymbol(s)) ci3opt(color(red)) ///
		xtitle("Latino Litigant", size(medium))  ///
		ytitle("") title("") saving(latinoint, replace)
		
*Put it all together:
	grc1leg whiteint.gph blackint.gph latinoint.gph, ycommon col(3) saving(figure2, replace)

